/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package maincz.tests.webapp.utils.scheduling;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import maincz.tests.webapp.utils.scheduling.actions.IAction;

/**
 *
 * @author Main
 */
public class SimpleScheduler implements IScheduler {

    private String name;    
    
    protected Queue<IAction> queue;
    
    private Thread thread = null;
    
    private Runnable process = new Runnable() {

        @Override
        public void run() {
            while(!queue.isEmpty()) {
                IAction action = queue.poll();
                if (action != null) {
                    action.run();
                }
            }
        }
    };           
    
    public SimpleScheduler(String name) {
        super();        
        this.queue = new ConcurrentLinkedQueue<IAction>();
        this.name = name;
        this.thread = new Thread(this.process);
    }
    
    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void start() {        
        this.thread.start();
    }

    @Override
    public void pushAction(IAction action) {
        this.queue.add(action);
    }
    
    public void status() {
        //this.thread.
    }            
    
}
